package com.ruoyi.business.controller;

import com.ruoyi.business.domain.TenantComponent;
import com.ruoyi.business.domain.TenantComponentComposite;
import com.ruoyi.business.service.ITenantComponentService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.EnterpriseAndApplicationCodeProperty;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 租户级复合组件Controller
 *
 * @author ruoyi
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/tenantComponent")
public class TenantComponentController extends BaseController
{
    @Autowired
    private ITenantComponentService tenantComponentService;

    /**
     * 查询租户级复合组件列表
     */
    @RequiresPermissions("business:tenantComponent:list")
    @GetMapping("/list")
    public TableDataInfo list(TenantComponent tenantComponent)
    {
        startPage();
        List<TenantComponent> list = tenantComponentService.selectTenantComponentList(tenantComponent);
        return getDataTable(list);
    }

    /**
     * 导出租户级复合组件列表
     */
    @RequiresPermissions("business:tenantComponent:export")
    @Log(title = "租户级复合组件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TenantComponent tenantComponent)
    {
        List<TenantComponent> list = tenantComponentService.selectTenantComponentList(tenantComponent);
        ExcelUtil<TenantComponent> util = new ExcelUtil<TenantComponent>(TenantComponent.class);
        util.exportExcel(response, list, "租户级复合组件数据");
    }

    /**
     * 获取租户级复合组件详细信息
     */
    @RequiresPermissions("business:tenantComponent:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tenantComponentService.selectTenantComponentById(id));
    }

    /**
     * 新增租户级复合组件
     */
    @RequiresPermissions("business:tenantComponent:add")
    @Log(title = "租户级复合组件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@EnterpriseAndApplicationCodeProperty TenantComponent tenantComponent)
    {
        return toAjax(tenantComponentService.insertTenantComponent(tenantComponent));
    }

    /**
     * 修改租户级复合组件
     */
    @RequiresPermissions("business:tenantComponent:edit")
    @Log(title = "租户级复合组件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@EnterpriseAndApplicationCodeProperty TenantComponent tenantComponent)
    {
        return toAjax(tenantComponentService.updateTenantComponent(tenantComponent));
    }

    /**
     * 删除租户级复合组件
     */
    @RequiresPermissions("business:tenantComponent:remove")
    @Log(title = "租户级复合组件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tenantComponentService.deleteTenantComponentByIds(ids));
    }
    /**
     * 提交新增租户组件功能点
     */
    @RequiresPermissions("business:tenantComponent:add")
    @Log(title = "租户组件功能点主表", businessType = BusinessType.INSERT)
    @PostMapping("/commitadd")
    public AjaxResult commitAdd(@RequestBody TenantComponentComposite tenantComponentComposite)
    {
        return AjaxResult.success(tenantComponentService.commitAdd(tenantComponentComposite));
    }
    /**
     * 提交更新租户组件功能点
     */
    @RequiresPermissions("business:tenantComponent:update")
    @Log(title = "租户组件功能点主表", businessType = BusinessType.UPDATE)
    @PostMapping("/commitupdate")
    public AjaxResult commitUpdate(@RequestBody TenantComponentComposite tenantComponentComposite)
    {
        return toAjax(tenantComponentService.commitUpdate(tenantComponentComposite));
    }
    /**
     * 保存新增租户组件功能点
     */
    @RequiresPermissions("business:tenantComponent:addDraft")
    @Log(title = "租户组件功能点主表", businessType = BusinessType.INSERT)
    @PostMapping("/insertDraftTenantComposite")
    public AjaxResult insertDraftComposite(@RequestBody TenantComponentComposite tenantComponentComposite)
    {
        return AjaxResult.success(tenantComponentService.insertDraftComposite(tenantComponentComposite));
    }
    /**
     * 保存更新租户组件功能点
     */
    @RequiresPermissions("business:tenantComponent:updateDraft")
    @Log(title = "租户组件功能点主表", businessType = BusinessType.UPDATE)
    @PostMapping("/updateDraftTenantComposite")
    public AjaxResult updateDraftComposite(@RequestBody TenantComponentComposite tenantComponentComposite)
    {
        return AjaxResult.success(tenantComponentService.updateDraftComposite(tenantComponentComposite));
    }
}
